package com.jg.blog.advice;

import com.jg.blog.exception.BlogException;
import com.jg.blog.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class BlogExceptionAdvice {
    /**
     * 全局异常处理器
     * @param blogException
     * @return
     */
    @ExceptionHandler(BlogException.class)
    public Result<?> exceptionHandler(BlogException blogException) {
        log.error("统一异常处理：", blogException);
        return new Result<>(blogException.getErrorCode(), blogException.getMessage());
    }
}
